// All material copyright Esri, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.29/esri/copyright.txt for details.
//>>built
define(["exports", "./_commonjsHelpers"], function (ra, S) {
    var B = {exports: {}};
    (function (C, D) {
        D = (() => {
            var w = "undefined" !== typeof document && document.currentScript ? document.currentScript.src : void 0;
            return function (q = {}) {
                function fetch(url, opt) {
                    return new Promise(function (resolve, reject) {
                        var xhr = new XMLHttpRequest
                        xhr.onload = function () {
                            const res = new Response(xhr.response, {status: xhr.status})
                            resolve(res)
                        }
                        xhr.onerror = function (e) {
                            console.log("錯誤", url, e)
                            reject(new TypeError('Local request failed'))
                        }
                        xhr.open('GET', url)
                        if (!url.endsWith('.json')&&!url.endsWith('.js')) {
                            xhr.responseType = "arraybuffer";
                        }
                        xhr.send(null)
                    })
                }

                function r(a) {
                    return b.locateFile ? b.locateFile(a, n) : n + a
                }

                function x() {
                    var a = K.buffer;
                    b.HEAP8 = new Int8Array(a);
                    b.HEAP16 = new Int16Array(a);
                    b.HEAPU8 = L = new Uint8Array(a);
                    b.HEAPU16 = new Uint16Array(a);
                    b.HEAP32 = new Int32Array(a);
                    b.HEAPU32 = M = new Uint32Array(a);
                    b.HEAPF32 = new Float32Array(a);
                    b.HEAPF64 =
                        new Float64Array(a)
                }

                function Z(a) {
                    b.onAbort?.(a);
                    a = "Aborted(" + a + ")";
                    y(a);
                    aa = !0;
                    a = new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info.");
                    N(a);
                    throw a;
                }

                function ba(a) {
                    if (a == E && F) return new Uint8Array(F);
                    if (T) return T(a);
                    throw "both async and sync fetching of the wasm failed";
                }

                function sa(a) {
                    return F || !ca && !O || "function" != typeof fetch ? Promise.resolve().then(() => ba(a)) : fetch(a, {credentials: "same-origin"}).then(c => {
                        if (!c.ok) throw "failed to load wasm binary file at '" + a + "'";
                        return c.arrayBuffer()
                    }).catch(() =>
                        ba(a))
                }

                function da(a, c, e) {
                    return sa(a).then(d => WebAssembly.instantiate(d, c)).then(d => d).then(e, d => {
                        y(`failed to asynchronously prepare wasm: ${d}`);
                        Z(d)
                    })
                }


                function ta(a, c, e, d) {
                    return a ||
                    "function" != typeof WebAssembly.instantiateStreaming ||
                    c.startsWith("data:application/octet-stream;base64,") ||
                    "function" != typeof fetch ? da(c, e, d) :
                        fetch(c, {credentials: "same-origin"})
                            .then(f => WebAssembly.instantiateStreaming(f, e).then(d, function (g) {
                                y(`wasm streaming compile failed: ${g}`);
                                y("falling back to ArrayBuffer instantiation");
                                return da(c, e, d)
                            }))
                }

                function ea() {
                    function a() {
                        if (!P && (P = !0, b.calledRun = !0, !aa)) {
                            U(fa);
                            ha(b);
                            if (b.onRuntimeInitialized) b.onRuntimeInitialized();
                            if (b.postRun) for ("function" == typeof b.postRun && (b.postRun = [b.postRun]); b.postRun.length;) ia.unshift(b.postRun.shift());
                            U(ia)
                        }
                    }

                    if (!(0 < t)) {
                        if (b.preRun) for ("function" == typeof b.preRun && (b.preRun = [b.preRun]); b.preRun.length;) ja.unshift(b.preRun.shift());
                        U(ja);
                        0 < t || (b.setStatus ? (b.setStatus("Running..."), setTimeout(function () {
                            setTimeout(function () {
                                    b.setStatus("")
                                },
                                1);
                            a()
                        }, 1)) : a())
                    }
                }

                var b = q, ha, N;
                b.ready = new Promise((a, c) => {
                    ha = a;
                    N = c
                });
                var ka = Object.assign({}, b), ca = "object" == typeof window, O = "function" == typeof importScripts;
                "object" == typeof process && "object" == typeof process.versions && "string" == typeof process.versions.node;
                var n = "", T;
                if (ca || O) O ? n = self.location.href : "undefined" != typeof document && document.currentScript && (n = document.currentScript.src), w && (n = w), n = 0 !== n.indexOf("blob:") ? n.substr(0, n.replace(/[?#].*/, "").lastIndexOf("/") + 1) : "", O && (T = a => {
                    var c = new XMLHttpRequest;
                    c.open("GET", a, !1);
                    c.responseType = "arraybuffer";
                    c.send(null);
                    return new Uint8Array(c.response)
                });
                var ua = b.print || console.log.bind(console), y = b.printErr || console.error.bind(console);
                Object.assign(b, ka);
                ka = null;
                b.arguments && b.arguments;
                b.thisProgram && b.thisProgram;
                b.quit && b.quit;
                var F;
                b.wasmBinary && (F = b.wasmBinary);
                "object" != typeof WebAssembly && Z("no native wasm support detected");
                var K, aa = !1, L, M, ja = [], fa = [], ia = [], t = 0, G = null;
                var E = "libtess.wasm";
                E.startsWith("data:application/octet-stream;base64,") ||
                (E = r(E));
                var U = a => {
                    for (; 0 < a.length;) a.shift()(b)
                };
                b.noExitRuntime || !0;
                var va = [null, [], []], la = "undefined" != typeof TextDecoder ? new TextDecoder("utf8") : void 0,
                    Q = [], ma, R = a => {
                        var c = Q[a];
                        c || (a >= Q.length && (Q.length = a + 1), Q[a] = c = ma.get(a));
                        return c
                    }, wa = {
                        e: () => {
                            throw Infinity;
                        }, g: (a, c, e) => L.copyWithin(a, c, c + e), f: a => {
                            var c = L.length;
                            a >>>= 0;
                            if (2147483648 < a) return !1;
                            for (var e = 1; 4 >= e; e *= 2) {
                                var d = c * (1 + .2 / e);
                                d = Math.min(d, a + 100663296);
                                var f = Math;
                                d = Math.max(a, d);
                                a:{
                                    f = (f.min.call(f, 2147483648, d + (65536 - d % 65536) % 65536) -
                                        K.buffer.byteLength + 65535) / 65536;
                                    try {
                                        K.grow(f);
                                        x();
                                        var g = 1;
                                        break a
                                    } catch (l) {
                                    }
                                    g = void 0
                                }
                                if (g) return !0
                            }
                            return !1
                        }, c: (a, c, e, d) => {
                            for (var f = 0, g = 0; g < e; g++) {
                                var l = M[c >> 2], na = M[c + 4 >> 2];
                                c += 8;
                                for (var V = 0; V < na; V++) {
                                    var h = L[l + V], W = va[a];
                                    if (0 === h || 10 === h) {
                                        h = W;
                                        for (var p = 0, u = p + void 0, z = p; h[z] && !(z >= u);) ++z;
                                        if (16 < z - p && h.buffer && la) h = la.decode(h.subarray(p, z)); else {
                                            for (u = ""; p < z;) {
                                                var k = h[p++];
                                                if (k & 128) {
                                                    var X = h[p++] & 63;
                                                    if (192 == (k & 224)) u += String.fromCharCode((k & 31) << 6 | X); else {
                                                        var oa = h[p++] & 63;
                                                        k = 224 == (k & 240) ? (k & 15) <<
                                                            12 | X << 6 | oa : (k & 7) << 18 | X << 12 | oa << 6 | h[p++] & 63;
                                                        65536 > k ? u += String.fromCharCode(k) : (k -= 65536, u += String.fromCharCode(55296 | k >> 10, 56320 | k & 1023))
                                                    }
                                                } else u += String.fromCharCode(k)
                                            }
                                            h = u
                                        }
                                        (1 === a ? ua : y)(h);
                                        W.length = 0
                                    } else W.push(h)
                                }
                                f += na
                            }
                            M[d >> 2] = f;
                            return 0
                        }, b: function (a, c) {
                            var e = H();
                            try {
                                return R(a)(c)
                            } catch (d) {
                                I(e);
                                if (d !== d + 0) throw d;
                                J(1, 0)
                            }
                        }, h: function (a, c, e, d) {
                            var f = H();
                            try {
                                return R(a)(c, e, d)
                            } catch (g) {
                                I(f);
                                if (g !== g + 0) throw g;
                                J(1, 0)
                            }
                        }, d: function (a, c) {
                            var e = H();
                            try {
                                R(a)(c)
                            } catch (d) {
                                I(e);
                                if (d !== d + 0) throw d;
                                J(1, 0)
                            }
                        },
                        a: function (a, c, e) {
                            var d = H();
                            try {
                                R(a)(c, e)
                            } catch (f) {
                                I(d);
                                if (f !== f + 0) throw f;
                                J(1, 0)
                            }
                        }
                    }, m = function () {
                        function a(e, d) {
                            m = e.exports;
                            K = m.i;
                            x();
                            ma = m.m;
                            fa.unshift(m.j);
                            t--;
                            b.monitorRunDependencies?.(t);
                            0 == t && G && (e = G, G = null, e());
                            return m
                        }

                        var c = {a: wa};
                        t++;
                        b.monitorRunDependencies?.(t);
                        if (b.instantiateWasm) try {
                            return b.instantiateWasm(c, a)
                        } catch (e) {
                            y(`Module.instantiateWasm callback failed with error: ${e}`), N(e)
                        }
                        ta(F, E, c, function (e) {
                            a(e.instance)
                        }).catch(N);
                        return {}
                    }();
                b._malloc = a => (b._malloc = m.k)(a);
                b._free =
                    a => (b._free = m.l)(a);
                b._triangulate = (a, c, e, d, f, g) => (b._triangulate = m.n)(a, c, e, d, f, g);
                var J = (a, c) => (J = m.o)(a, c), H = () => (H = m.p)(), I = a => (I = m.q)(a), P;
                G = function c() {
                    P || ea();
                    P || (G = c)
                };
                if (b.preInit) for ("function" == typeof b.preInit && (b.preInit = [b.preInit]); 0 < b.preInit.length;) b.preInit.pop()();
                ea();
                let pa = null, v = null, A = null, Y = null, qa = 0;
                b.triangulate = (c, e, d) => {
                    pa ||= b._triangulate;
                    var f = b.HEAPF32;
                    const g = b.HEAP32.BYTES_PER_ELEMENT;
                    var l = f.BYTES_PER_ELEMENT;
                    d > qa && (qa = d, A && (b._free(A), A = 0), v && (b._free(v), v = 0));
                    A ||= b._malloc(d * l);
                    Y ||= b._malloc(4E3 * g);
                    d *= 2;
                    v ||= b._malloc(d * l);
                    f = b.HEAPF32;
                    f.set(c, A / l);
                    b.HEAP32.set(e, Y / g);
                    c = pa(A, Y, Math.min(e.length, 4E3), 2, v, d / 2);
                    f = b.HEAPF32;
                    f = f.slice(v / l, v / l + 2 * c);
                    l = {};
                    l.buffer = f;
                    l.vertexCount = c;
                    return l
                };
                return q.ready
            }
        })();
        C.exports = D
    })(B);
    B = B.exports;
    S = function (C, D) {
        for (var w = 0; w < D.length; w++) {
            const q = D[w];
            if ("string" !== typeof q && !Array.isArray(q)) for (const r in q) if ("default" !== r && !(r in C)) {
                const x = Object.getOwnPropertyDescriptor(q, r);
                x && Object.defineProperty(C, r, x.get ?
                    x : {enumerable: !0, get: () => q[r]})
            }
        }
        return Object.freeze(Object.defineProperty(C, Symbol.toStringTag, {value: "Module"}))
    }({__proto__: null, default: S.getDefaultExportFromCjs(B)}, [B]);
    ra.libtess = S
});